<?php
namespace app\admin\model;

class Shareholderinfo extends Base{

    protected $name = 'shareholder_info';

    //删除
    public function delStockShareholderinfo($sid=0, $stock_code=''){
        $this->where(['sid'=>$sid,'stock_code'=>$stock_code])->delete();
    }

    //股东信息
    public function handleStockShareholderinfo($arr=[],$sid='', $stock_code=''){

        $data = [];

        $data['gdrs'] = sprintf("%.2f",floatval($arr[0]['HOLDER_TOTAL_NUM'])/10000);
        $data['early_phase_change'] = sprintf("%.2f", $arr[0]['TOTAL_NUM_RATIO']);
        $data['per_capita_circulate'] = sprintf("%.3f", $arr[0]['AVG_FREE_SHARES']/10000);
        $data['chip_concentration'] = trim($arr[0]['HOLD_FOCUS']);
        $data['shares'] = trim($arr[0]['PRICE']);
        $data['per_capita_share_holding_money'] = sprintf("%.2f", trim($arr[0]['AVG_HOLD_AMT'])/10000);
        $data['ten_shareholders_hold_shares_aggregate'] = sprintf("%.2f", trim($arr[0]['HOLD_RATIO_TOTAL']));
        $data['ten_tradable_shareholders_hold_shares_total'] = sprintf("%.2f", trim($arr[0]['FREEHOLD_RATIO_TOTAL']));
        $data['end_date'] = date('Y-m-d', strtotime(trim($arr[0]['END_DATE'])));

        $reVal = $this->detailShareholderinfo(['sid'=>$sid, 'stock_code'=>$stock_code]);
        if(!empty($reVal['si_id'])){
            $this->where(['si_id'=>$reVal['si_id']])->update($data);
        }else{
            $data['sid'] = $sid;
            $data['stock_code'] = $stock_code;
            $this->insert($data);
        }
    }

    //详情
    public function detailShareholderinfo($where = null){
    	return $this->where($where)->find();
    }
}